package com.jiazhong.backend.test;

import com.jiazhong.backend.service.BookService;
import com.jiazhong.commons.bean.Book;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;

import java.util.List;

@SpringBootTest
@Component
@Slf4j
public class BookApp {
    @Resource
    private BookService service;

    //新增数据
    @Test
    public void a(){
        Book book = new Book();
        book.setName("当幸福来敲门");
        book.setPrice(20.0);
        book.setCategoryId("1521453234854564569");
        service.save(book);
    }

    //删除
    @Test
    public void b(){
        boolean removeById = service.removeById("1844937639328374785");
        log.info("remove:{}",removeById);
    }

    //修改
    @Test
    public void c(){
        Book book = new Book();
        book.setId("1853286663313227778");
        book.setName("闻香识女人");
        book.setPrice(21.0);
        book.setAuthor("美国人");
        book.setPublisher("华纳");
        boolean updateById = service.updateById(book);
    }

    @Test
    public void d(){
        List<Book> list = service.list();
        list.forEach(System.out::println);
    }
}
